package com.atguigu.common.vaild;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

/**
 * 版权：(C) 版权所有  上海天好电子商务有限公司苏州分公司
 * <简述>
 * <详细描述>
 *
 * @author syf
 * @version 1.0
 * @see
 * @since
 */
public class LisyValueConstraintValidator implements ConstraintValidator<ListValue, Integer> {

    private Set<Integer> set = new HashSet<>();
    //初始化
    @Override
    public void initialize(ListValue constraintAnnotation) {
        int[] valus = constraintAnnotation.valus();
        for (int bal: valus) {
            set.add(bal);
        }
    }

    //判斷是否校驗成功
    /**
     * @author yefei.shi
     * @param integer: 需要校驗的值
     * @param constraintValidatorContext: 
    
     * @return boolean
     */

    @Override
    public boolean isValid(Integer integer, ConstraintValidatorContext constraintValidatorContext) {
        return set.contains(integer);
    }
}
